<?php
//include("../../db/DBConnection.php");
//DataBase::createConection();
include("../../db/cart_db.php");
include("../../db/cart_functions.php");

if (isset($_REQUEST['command']) && isset($_REQUEST['productid'])) {
    if ($_REQUEST['command'] == 'add' && $_REQUEST['productid'] > 0) {
        $pid = $_REQUEST['productid'];
        addtocart($pid, 1);
        header("location:shoppingcart.php");
        exit();
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Bfat</title>
        <!-- <link rel="shortcut icon" href="../imagens/favicon.ico" /> -->
        <link href="../../viewer/css/styles.css" rel="stylesheet" type="text/css" />
        <link href="../../viewer/css/button.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="../js/scripts.js"></script>
        <script language="javascript">
            function addtocart(pid){
                document.form1.productid.value=pid;
                document.form1.command.value='add';
                document.form1.submit();
            }
        </script>
        <style>
            div#side-col
            {
                width: auto;
                left: 240px;
                margin: -100px 240px 0px 0px;
            }
            td{
                padding:15px;
                background-color:#FFFFFF;

            }
        </style>
    </head>


    <body>
        <div id="banner">
            <center><a href="../../viewer/vIndex.php"><img width="200" height="200" src="../../viewer/images/logo.png" /></a>
                <nav><ul>
                        <li><a href="../../viewer/shopping_cart/products.php">Cardápio</a></li>
                        <li><a href="../../viewer/vLocalizacao.php">Localização</a></li>
                        <li><a href="../../viewer/vFotos.php">Fotos</a></li>
                        <li><a href="../../viewer/vContato.php">Contato</a></li>
                        <li><a href="../../viewer/vLogin.php">Painel de controle</a></li>

                    </ul></nav></center>
        </div>

        <div id="side-col">
            <p><a href="../../viewer/vIndex.php"><img src="../../viewer/images/back_button_mp.png" title="Voltar" alt="Voltar"/></a>
                <?php
                if (isset($_SESSION['usuario'])) {
                    echo "<a href='../../viewer/vCadastroProdutos.php'><img src='../../viewer/images/database_add.png' title='Adicionar novo produto' alt='Adicionar novo produto'/></a>";
                }
                ?></p>
            <form name="form1">
                <input type="hidden" name="productid" />
                <input type="hidden" name="command" />
            </form>
            <div align="center">
                <!-- <h1 align="center">Cardápio</h1>-->
                <table border="0" >
                    <tr><td colspan="2"><hr size="1" /></td></tr>
                    <?php
                    $result = mysql_query("select * from produtos") or die("select * from produtos" . "<br/><br/>" . mysql_error());
                    while ($row = mysql_fetch_array($result)) {
                        ?>
                        <tr>
                            <!--<td><img src="<?php //echo $row['imagem']           ?>" width="150" height="147"/></td>-->
                            <td><img src="../../viewer/shopping_cart/getProductImage.php?serial=<?php echo $row['serial'] ?>" width="150" height="147"/></td>
                            <td>   	<b><?php echo $row['nome'] ?></b><br />
                                <?php echo $row['descricao'] ?><br />
                                Preço:<big style="color:green">
                                    R$<?php echo $row['preco'] ?></big><br /><br />
                                <p><input type="image" src="../../viewer/images/shopping_cart_add_small.png" value="Add to Cart" onclick="addtocart(<?php echo $row['serial'] ?>)" />
                                    <?php
                                    $serial = 0;
                                    if (isset($_SESSION['usuario'])) {
                                        $serial = $row['serial'];
                                        echo "<a href='../../viewer/vEditarProduto.php?serial=";
                                        echo $row['serial'];
                                        echo "'>";
                                        echo "<img src='../../viewer/images/database_edit_small.png' title='Editar produto' alt='Editar produto'/></a>";
                                        //echo "<a href='../../controller/cExcluirProduto.php?serial=";
                                        //echo $row['serial'];
                                        //echo "'>";
                                        echo "<a href='#' onClick='confirmar_exclusao($serial)'";
                                        echo "'>";
                                        echo "<img src='../../viewer/images/excluir_database_small.png' title='Excluir produto' alt='Excluir produto'/></a>";
                                    }
                                    ?>
                                </p>
                            </td>
                        </tr>
                        <tr><td colspan="2"><hr size="1" /></td></tr>
                    <?php } ?>
                </table>
            </div>
            <p><a href="../../viewer/vIndex.php"><img src="../../viewer/images/back_button_mp.png" title="Voltar" alt="Voltar"/></a>
                <?php
                if (isset($_SESSION['usuario'])) {
                    echo "<a href='../../viewer/vCadastroProdutos.php'><img src='../../viewer/images/database_add.png' title='Adicionar novo produto' alt='Adicionar novo produto'/></a>";
                }
                ?>
            </p>
        </div>
        <br></br>
    </body>
    <footer>
        <?php require("../../viewer/vLayoutFooter.php"); ?>
    </footer>
</html>